//路由守卫
import router from '@/router';
import store from '@/store';
import {getCookies} from '@/utils/cookies';

const whiteList = ['/signin'];// no redirect whitelist

router.beforeEach((to,from,next)=>{
    console.log('to.path:',to.path);
    console.log('from.path:',from.path);
    console.log('getCookies():',getCookies());
    console.log('store:',store);

    if(getCookies()){
        if(whiteList.includes(to.path)){
            next({path:'/index'});
        }else{
            if(store.state.user.uid){
                next();
            }else{//
                console.log('dispatch::GetUserInfo');
                store.dispatch('user/GetUserInfo',{});
                next();
            }
        }
    }else{
        if(whiteList.includes(to.path)){
            next();
        }else{
            next({path:`/signin?redirect=${to.path}`});
        }
    }
});